// pages/concern/concern.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shoplist:'',
    zitiid:'',
    lng:'',
    lat:'',
    num:'',
    select:'',
    index:''
  },
  xuanzhong:function(e){
    // console.log(e.currentTarget)
    for (var a in this.data.shoplist){
      var zitiname = this.data.shoplist[a].ShopName;
    }
    console.log(zitiname,'zitiname')
    var id=e.currentTarget.dataset.id
    var select = this.data.select;
    var index = this.data.index
    // wx.navigateBack({
    //   delta: 1
    // })
    wx.redirectTo({
      url: '/pages/groupbuy/groupbuy?zitiids=' + id + '&zitiname=' + zitiname + '&select=' + select + '&index=' + index,
    })
  },
  getlist(){
    // console.log(wx.getStorageSync('a'),'sasd')
    this.setData({
      lng : wx.getStorageSync('longitude'),
       lat : wx.getStorageSync('latitude')
    })
    var lng = wx.getStorageSync('longitude')
    var lat = wx.getStorageSync('latitude')
    ajax('/api/ShopAddress/Get?requestContent=' + JSON.stringify({
      CheckFlag:2,
      GroupbuyingID: this.data.zitiid,
      lng: this.data.lng,
      lat: this.data.lat,
      token: wx.getStorageSync('Access_token'),

    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        console.log(res)
        this.setData({
          shoplist: res.Models
        })
        for(var a in this.data.shoplist){
          var num = parseFloat(this.data.shoplist[a].distance).toFixed(2)
          this.setData({
            num:num
          })
        }
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000',
    })
    this.setData({
      zitiid:options.id,
      select:options.select,
      index:options.index
    })
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})